package com.shop.shopserver.config;

import com.shop.shopserver.filter.HierarchicalBloomFilter;
import com.shop.shopserver.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class HierarchicalBloomFilterConfiguration {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    private GoodsMapper goodsMapper;
    @Bean
    public HierarchicalBloomFilter hierarchicalBloomFilterInit() {
        // 新建一个层级的布隆过滤器
        HierarchicalBloomFilter hierarchicalBloomFilter = new HierarchicalBloomFilter(
                new int[]{10000, 10000, 10000},
                new int[]{1, 1, 1},
                new int[]{1, 3, 3},
                redisTemplate,
                goodsMapper);
        // 初始化存储访问次数的zset和层级过滤器
        hierarchicalBloomFilter.init();
        return hierarchicalBloomFilter;
    }
}
